package com.hzbank.tcps.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.ApiResponse;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.catalina.User;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
 
 
@Api(value="/test", tags="swaggerdemo")
@RestController
@Slf4j
@RequestMapping("/test")
public class TestSwaggerController {
 
	
	/*@Api：用在类上，说明该类的作用
	@ApiOperation：用在方法上，说明方法的作用
	@ApiImplicitParams：用在方法上包含一组参数说明
	@ApiImplicitParam：用在@ApiImplicitParams注解中，指定一个请求参数的各个方面
		paramType：参数放在哪个地方
			header-->请求参数的获取：@RequestHeader
			query-->请求参数的获取：@RequestParam
			path（用于restful接口）-->请求参数的获取：@PathVariable
			body（不常用）
			form（不常用）
		name：参数名
		dataType：参数类型
		required：参数是否必须传
		value：参数的意思
		defaultValue：参数的默认值
	@ApiResponses：用于表示一组响应
	@ApiResponse：用在@ApiResponses中，一般用于表达一个错误的响应信息
		code：数字，例如400
		message：信息，例如"请求参数没填好"
		response：抛出异常的类
	@ApiModel：描述一个Model的信息（这种一般用在post创建的时候，使用@RequestBody这样的场景，请求参数无法使用@ApiImplicitParam注解进行描述的时候）
	@ApiModelProperty：描述一个model的属性
	@ApiIgnore()用于类或者方法上，可以不被swagger显示在页面上 

	*/
	
 
	/**
	 * 根据ID查询用户
	 * @param id
	 * @return
	 */
	@ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息")
	@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer", paramType = "path")
	@RequestMapping(value = "user/{id}", method = RequestMethod.GET)
	public ResponseEntity<Object> getUserById (@PathVariable(value = "id") Integer id){
		Object r = new Object();
		return ResponseEntity.ok(r);
	}
 
	
/*	@ApiImplicitParam() 用于方法 
	表示单独的请求参数 
	@ApiImplicitParams() 用于方法，包含多个 @ApiImplicitParam 
		name–参数ming 
		value–参数说明 
		dataType–数据类型 
		paramType–参数类型 
		example–举例说明
	*/
	@ApiOperation("查询测试")
	  @GetMapping("select")
	  //@ApiImplicitParam(name="name",value="用户名",dataType="String", paramType = "query")
	  @ApiImplicitParams({
	  @ApiImplicitParam(name="name",value="用户名",dataType="string", paramType = "query",example="xingguo"),
	  @ApiImplicitParam(name="id",value="用户id",dataType="long", paramType = "query")})
	  public void select(){

	  }
	/**
	 * 查询用户列表
	 * @return
	 */
	@ApiOperation(value="获取用户列表", notes="获取用户列表")
	@RequestMapping(value = "users", method = RequestMethod.GET)
	@ApiResponse(code = 200, message = "Successful")
	public ResponseEntity<Object> getUserList (){
		Object r = new Object();
		return ResponseEntity.ok(r);
	}
 
	/**
	 * 添加用户
	 * @param user
	 * @return
	 */
	@ApiOperation(value="创建用户", notes="根据User对象创建用户")
	@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
	@RequestMapping(value = "user", method = RequestMethod.POST)
	public ResponseEntity<Object> add (@RequestBody User user){
		Object r = new Object();
		return ResponseEntity.ok(r);
	}
 
	/**
	 * 根据id删除用户
	 * @param id
	 * @return
	 */
	@ApiOperation(value="删除用户", notes="根据url的id来指定删除用户")
	@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long", paramType = "path")
	@RequestMapping(value = "user/{id}", method = RequestMethod.DELETE)
	public ResponseEntity<Object> delete (@PathVariable(value = "id") Integer id){
		Object r = new Object();
		return ResponseEntity.ok(r);
	}
 
	/**
	 * 根据id修改用户信息
	 * @param user
	 * @return
	 */
	@ApiOperation(value="更新信息", notes="根据url的id来指定更新用户信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long",paramType = "path"),
			@ApiImplicitParam(name = "user", value = "用户实体user", required = true, dataType = "User")
	})
	@RequestMapping(value = "user/{id}", method = RequestMethod.PUT)
	public ResponseEntity<Object> update (@PathVariable("id") Integer id, @RequestBody User user){
		Object r = new Object();
		return ResponseEntity.ok(r);
	}
 
	@ApiIgnore//使用该注解忽略这个API
	@RequestMapping(value = "/hi", method = RequestMethod.GET)
	public String  jsonTest() {
		return " hi you!";
	}
	  @ApiOperation(value = "查询车辆接口", notes = "此接口描述xxxxxxxxxxxxx<br/>xxxxxxx<br>值得庆幸的是这儿支持html标签<hr/>", response = String.class)
	    @ApiImplicitParams({
	            @ApiImplicitParam(name = "vno", value = "车牌", required = false,
	                    dataType = "string", paramType = "query", defaultValue = "辽A12345"),
	            @ApiImplicitParam(name = "page", value = "page", required = false,
	                    dataType = "Integer", paramType = "query",defaultValue = "1"),
	            @ApiImplicitParam(name = "count", value = "count", required = false,
	                    dataType = "Integer", paramType = "query",defaultValue = "10")
	    })
	    @ApiResponses(value = {
	            @ApiResponse(code = 200, message = "Successful — 请求已完成"),
	            @ApiResponse(code = 400, message = "请求中有语法问题，或不能满足请求"),
	            @ApiResponse(code = 401, message = "未授权客户机访问数据"),
	            @ApiResponse(code = 404, message = "服务器找不到给定的资源；文档不存在"),
	            @ApiResponse(code = 500, message = "服务器不能完成请求")}
	    )
	    @ResponseBody
	    @RequestMapping(value = "", method = RequestMethod.GET)
	    public Map<String,Object> findVehicles(@RequestParam(value = "vno", required = false) String vno,
	                                 @RequestParam(value = "page", required = false) Integer page,
	                                 @RequestParam(value = "count", required = false) Integer count)
	            throws Exception {

	        log.info("http://localhost:8501/api/v1/vehicles");
	        log.info("## {},{},{}", vno, page, count);
	        log.info("## 请求时间：{}", new Date());

	        Map<String, Object> map = new HashMap<>();
	        map.put("vno", vno);
	        map.put("page", page);
	        return map;
	    }
}
